home *** CD-ROM | disk | FTP | other *** search
/ Hyper Animation Series: Viper (Limited Edition) / Hyper Animation Series: VIPER (Limited Edition).iso / pc / SYSTEM / class / JglFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-08-04  |  7.7 KB  |  414 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Event;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.MediaTracker;
  9. import java.awt.Toolkit;
  10. import java.io.FileInputStream;
  11. import java.io.InputStream;
  12. import java.net.URL;
  13.  
  14. public class JglFrame extends Applet implements Runnable {
  15.    public static final String VERSION = "VIPER STG for JAVA";
  16.    private Thread tMain;
  17.    private GameFrame gameframe;
  18.    protected int Width = 320;
  19.    protected int Height = 240;
  20.    protected boolean fApplication = false;
  21.    protected int RefreshRate = 16;
  22.    private long StartFrame;
  23.    private long EndFrame;
  24.    private long WaitFrame;
  25.    protected Image iOffscreen;
  26.    protected Graphics gOffscreen;
  27.    protected Bg bg1;
  28.    protected Sprite sprite;
  29.    protected SpriteAnime spriteanime;
  30.    protected JglPad jglpad;
  31.    private short KeyNomal;
  32.    // $FF: renamed from: SE Sound
  33.    protected Sound field_0;
  34.    protected Sound BGM;
  35.    protected int CurtainHeight;
  36.    protected int MovieHeight;
  37.    protected boolean fFlush;
  38.    protected boolean fFocus;
  39.  
  40.    public void setSizeWidth(int var1) {
  41.       this.Width = var1;
  42.    }
  43.  
  44.    public void setSizeHeight(int var1) {
  45.       this.Height = var1;
  46.    }
  47.  
  48.    public void setFlagApplication(boolean var1) {
  49.       this.fApplication = var1;
  50.    }
  51.  
  52.    public void setRefreshRate(int var1) {
  53.       this.RefreshRate = var1;
  54.    }
  55.  
  56.    public void setBg1(Bg var1) {
  57.       this.bg1 = var1;
  58.    }
  59.  
  60.    public void setSprite(Sprite var1) {
  61.       this.sprite = var1;
  62.    }
  63.  
  64.    public void setSpriteAnime(SpriteAnime var1) {
  65.       this.spriteanime = var1;
  66.    }
  67.  
  68.    public void setJglPad(JglPad var1) {
  69.       this.jglpad = var1;
  70.    }
  71.  
  72.    public void setSE(Sound var1) {
  73.       this.field_0 = var1;
  74.    }
  75.  
  76.    public void setBGM(Sound var1) {
  77.       this.BGM = var1;
  78.    }
  79.  
  80.    public void setCurtainHeight(int var1) {
  81.       this.CurtainHeight = var1;
  82.    }
  83.  
  84.    public void setMovieHeight(int var1) {
  85.       this.MovieHeight = var1;
  86.    }
  87.  
  88.    public void setFlush(boolean var1) {
  89.       this.fFlush = var1;
  90.    }
  91.  
  92.    public int getSizeWidth() {
  93.       return this.Width;
  94.    }
  95.  
  96.    public int getSizeHeight() {
  97.       return this.Height;
  98.    }
  99.  
  100.    public boolean getFlagApplication() {
  101.       return this.fApplication;
  102.    }
  103.  
  104.    public int getRefreshRate() {
  105.       return this.RefreshRate;
  106.    }
  107.  
  108.    public Bg getBg1() {
  109.       return this.bg1;
  110.    }
  111.  
  112.    public Sprite getSprite() {
  113.       return this.sprite;
  114.    }
  115.  
  116.    public SpriteAnime getSpriteAnime() {
  117.       return this.spriteanime;
  118.    }
  119.  
  120.    public JglPad getJglPad() {
  121.       return this.jglpad;
  122.    }
  123.  
  124.    public Sound getSE() {
  125.       return this.field_0;
  126.    }
  127.  
  128.    public Sound getBGM() {
  129.       return this.BGM;
  130.    }
  131.  
  132.    protected int getCurtainHeight() {
  133.       return this.CurtainHeight;
  134.    }
  135.  
  136.    protected int getMovieHeight() {
  137.       return this.MovieHeight;
  138.    }
  139.  
  140.    public boolean getFlush() {
  141.       return this.fFlush;
  142.    }
  143.  
  144.    public boolean getFocus() {
  145.       return this.fFocus;
  146.    }
  147.  
  148.    public InputStream openStream(String var1) {
  149.       Object var2 = null;
  150.  
  151.       try {
  152.          if (this.getFlagApplication()) {
  153.             var2 = new FileInputStream(var1);
  154.          } else {
  155.             var2 = (new URL(((Applet)this).getDocumentBase(), var1)).openStream();
  156.          }
  157.       } catch (Exception var3) {
  158.       }
  159.  
  160.       return (InputStream)var2;
  161.    }
  162.  
  163.    public Image getImage(String var1) {
  164.       MediaTracker var2 = new MediaTracker(this);
  165.       Image var3;
  166.       if (this.getFlagApplication()) {
  167.          var3 = Toolkit.getDefaultToolkit().getImage(var1);
  168.       } else {
  169.          var3 = super.getImage(((Applet)this).getCodeBase(), var1);
  170.       }
  171.  
  172.       var2.addImage(var3, 0);
  173.  
  174.       try {
  175.          var2.waitForAll();
  176.       } catch (InterruptedException var4) {
  177.       }
  178.  
  179.       return var3;
  180.    }
  181.  
  182.    public Image getImage(String var1, boolean var2) {
  183.       MediaTracker var3 = new MediaTracker(this);
  184.       Image var4;
  185.       if (this.getFlagApplication()) {
  186.          var4 = Toolkit.getDefaultToolkit().getImage(var1);
  187.       } else {
  188.          var4 = super.getImage(((Applet)this).getCodeBase(), var1);
  189.       }
  190.  
  191.       if (var2) {
  192.          var3.addImage(var4, 0);
  193.  
  194.          try {
  195.             var3.waitForAll();
  196.          } catch (InterruptedException var5) {
  197.          }
  198.       }
  199.  
  200.       return var4;
  201.    }
  202.  
  203.    public AudioClip getAudioClip(String var1) {
  204.       Object var2 = null;
  205.       AudioClip var3;
  206.       if (this.getFlagApplication()) {
  207.          var3 = null;
  208.       } else {
  209.          var3 = super.getAudioClip(((Applet)this).getCodeBase(), var1);
  210.       }
  211.  
  212.       return var3;
  213.    }
  214.  
  215.    public void init() {
  216.       this.fFocus = true;
  217.       ((Applet)this).resize(this.Width, this.Height);
  218.       ((Component)this).setBackground(Color.black);
  219.       this.iOffscreen = ((Component)this).createImage(this.Width, this.Height);
  220.       this.gOffscreen = this.iOffscreen.getGraphics();
  221.       this.sprite = new Sprite(this, 0);
  222.       this.spriteanime = new SpriteAnime(this.sprite, 0);
  223.       this.bg1 = new Bg(this, 3);
  224.       this.jglpad = new JglPad();
  225.       this.field_0 = new Sound(this, 0);
  226.       this.BGM = new Sound(this, 0);
  227.       this.gameframe = new StgFrame(this);
  228.    }
  229.  
  230.    public void start() {
  231.       this.tMain = new Thread(this);
  232.       if (this.tMain != null) {
  233.          this.tMain.start();
  234.       }
  235.  
  236.    }
  237.  
  238.    public void update(Graphics var1) {
  239.       this.paintAll(var1);
  240.    }
  241.  
  242.    public void paintAll(Graphics var1) {
  243.       if (this.MovieHeight == 0) {
  244.          var1.drawImage(this.iOffscreen, 0, 0, this);
  245.       } else {
  246.          var1.drawImage(this.iOffscreen, 0, this.MovieHeight, 320, 240 - this.MovieHeight * 2, this);
  247.       }
  248.    }
  249.  
  250.    public void run() {
  251.       while(true) {
  252.          this.StartFrame = System.currentTimeMillis();
  253.          this.gameframe.run();
  254.          this.spriteanime.action();
  255.          this.bg1.paint(this.gOffscreen);
  256.          this.sprite.paint(this.gOffscreen);
  257.          this.curtain(this.gOffscreen, Color.black, this.CurtainHeight);
  258.          this.Flush(this.gOffscreen, Color.white);
  259.          ((Component)this).repaint();
  260.          this.EndFrame = System.currentTimeMillis();
  261.          this.WaitFrame = (long)this.RefreshRate - (this.EndFrame - this.StartFrame);
  262.          if (this.WaitFrame > 0L) {
  263.             try {
  264.                Thread.sleep(this.WaitFrame);
  265.             } catch (Exception var2) {
  266.             }
  267.          } else {
  268.             try {
  269.                Thread.sleep((long)this.RefreshRate);
  270.             } catch (Exception var1) {
  271.             }
  272.          }
  273.  
  274.          this.jglpad.setNomal(this.KeyNomal);
  275.       }
  276.    }
  277.  
  278.    public void stop() {
  279.       this.gameframe.stop();
  280.       if (this.tMain != null) {
  281.          this.tMain.stop();
  282.          this.tMain = null;
  283.       }
  284.  
  285.    }
  286.  
  287.    private void curtain(Graphics var1, Color var2, int var3) {
  288.       if (var3 != 0) {
  289.          this.gOffscreen.setColor(var2);
  290.          this.gOffscreen.fillRect(0, 0, this.Width, var3);
  291.          this.gOffscreen.fillRect(0, this.Height - var3, this.Width, this.Height);
  292.       }
  293.  
  294.    }
  295.  
  296.    private void Flush(Graphics var1, Color var2) {
  297.       if (this.fFlush) {
  298.          this.gOffscreen.setColor(var2);
  299.          this.gOffscreen.fillRect(0, 0, this.Width, this.Height);
  300.       }
  301.  
  302.    }
  303.  
  304.    public boolean action(Event var1, Object var2) {
  305.       return this.gameframe.action(var1, var2);
  306.    }
  307.  
  308.    public boolean mouseUp(Event var1, int var2, int var3) {
  309.       return this.gameframe.mouseUp(var1, var2, var3);
  310.    }
  311.  
  312.    public boolean mouseDown(Event var1, int var2, int var3) {
  313.       return this.gameframe.mouseDown(var1, var2, var3);
  314.    }
  315.  
  316.    public boolean mouseMove(Event var1, int var2, int var3) {
  317.       return this.gameframe.mouseMove(var1, var2, var3);
  318.    }
  319.  
  320.    public boolean mouseDrag(Event var1, int var2, int var3) {
  321.       return this.gameframe.mouseDrag(var1, var2, var3);
  322.    }
  323.  
  324.    public boolean gotFocus(Event var1, Object var2) {
  325.       this.fFocus = true;
  326.       return this.gameframe.gotFocus(var1, var2);
  327.    }
  328.  
  329.    public boolean lostFocus(Event var1, Object var2) {
  330.       this.fFocus = false;
  331.       return this.gameframe.lostFocus(var1, var2);
  332.    }
  333.  
  334.    public void destroy() {
  335.       this.gameframe.destroy();
  336.    }
  337.  
  338.    public boolean keyDown(Event var1, int var2) {
  339.       switch (var2) {
  340.          case 50:
  341.          case 1005:
  342.             this.KeyNomal = (short)(this.KeyNomal | 32);
  343.             break;
  344.          case 52:
  345.          case 1006:
  346.             this.KeyNomal = (short)(this.KeyNomal | 64);
  347.             break;
  348.          case 54:
  349.          case 1007:
  350.             this.KeyNomal = (short)(this.KeyNomal | 128);
  351.             break;
  352.          case 56:
  353.          case 1004:
  354.             this.KeyNomal = (short)(this.KeyNomal | 16);
  355.             break;
  356.          case 67:
  357.          case 99:
  358.             this.KeyNomal = (short)(this.KeyNomal | 1);
  359.             break;
  360.          case 85:
  361.          case 117:
  362.             this.KeyNomal = (short)(this.KeyNomal | 2);
  363.             break;
  364.          case 88:
  365.          case 120:
  366.             this.KeyNomal = (short)(this.KeyNomal | 4);
  367.             break;
  368.          case 90:
  369.          case 122:
  370.             this.KeyNomal = (short)(this.KeyNomal | 8);
  371.       }
  372.  
  373.       return true;
  374.    }
  375.  
  376.    public boolean keyUp(Event var1, int var2) {
  377.       switch (var2) {
  378.          case 50:
  379.          case 1005:
  380.             this.KeyNomal = (short)(this.KeyNomal ^ 32);
  381.             break;
  382.          case 52:
  383.          case 1006:
  384.             this.KeyNomal = (short)(this.KeyNomal ^ 64);
  385.             break;
  386.          case 54:
  387.          case 1007:
  388.             this.KeyNomal = (short)(this.KeyNomal ^ 128);
  389.             break;
  390.          case 56:
  391.          case 1004:
  392.             this.KeyNomal = (short)(this.KeyNomal ^ 16);
  393.             break;
  394.          case 67:
  395.          case 99:
  396.             this.KeyNomal = (short)(this.KeyNomal ^ 1);
  397.             break;
  398.          case 85:
  399.          case 117:
  400.             this.KeyNomal = (short)(this.KeyNomal ^ 2);
  401.             break;
  402.          case 88:
  403.          case 120:
  404.             this.KeyNomal = (short)(this.KeyNomal ^ 4);
  405.             break;
  406.          case 90:
  407.          case 122:
  408.             this.KeyNomal = (short)(this.KeyNomal ^ 8);
  409.       }
  410.  
  411.       return true;
  412.    }
  413. }
  414.